<?php

namespace app\admin\services;

use app\admin\model\OrderInModel;
use think\facade\Db;

class SplitOrderService extends BaseService
{
    /**
     * 新建前三月数据表，导入数据
     * 创建新的数据表
     * @return void
     */
    public static function buildNewOrderTable($keepMonth)
    {
        $tableName='order_in_'.date('Ym',strtotime("- $keepMonth month"));
        $month=date('Y-m-01',strtotime('-  '.($keepMonth-1).'month'));
        $sql="CREATE TABLE $tableName SELECT * FROM order_in where create_time < '$month';";
//        Db::query("DROP TABLE IF EXISTS `$tableName`;");
        Db::query($sql);
        Db::query("alter table $tableName add primary key(id)");
        OrderInModel::where([['create_time','<',$month]])->delete();

    }
}
